
package com.jack.helloworld.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.MultiAutoCompleteTextView;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.jack.helloworld.R;
import com.jack.helloworld.activity.mode.BaseActivity;

public class Main01Activity extends BaseActivity implements CompoundButton.OnCheckedChangeListener,
        View.OnClickListener{

    Context context;

    TextView textView1;
    ImageButton imageButton;
    AutoCompleteTextView autoCompleteTextView;
    MultiAutoCompleteTextView multiAutoCompleteTextView;
    ToggleButton toggleButton;
    String[] infoList = new String[] {"android1", "android2", "joker", "jack", "keep moving"};

    Button buttonList;
    Button buttonSimpleList;
    Button buttonCalander;
    Button buttonDownload;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main01);

        context = this;
        getView();
        getDate();

    }


    private void getView() {
        textView1 = (TextView) findViewById(R.id.text1);
        imageButton = (ImageButton) findViewById(R.id.imageButton);
        autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
        multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView);
        toggleButton = (ToggleButton) findViewById(R.id.toggleButton);

        buttonList = (Button) findViewById(R.id.buttonList);
        buttonSimpleList = (Button) findViewById(R.id.buttonSimpleList);
        buttonCalander = (Button) findViewById(R.id.buttonCalandar);
        buttonDownload = (Button) findViewById(R.id.buttonDownload);
    }

    private void getDate() {
        //use marquee for textView
        textView1.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        textView1.setMarqueeRepeatLimit(-1);
        textView1.setSelected(true);
        textView1.setSingleLine();
        textView1.setFocusable(true);
        textView1.setFocusableInTouchMode(true);

        //use autoCompleteTextView
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                infoList);
        autoCompleteTextView.setAdapter(adapter);

        //use multiAutoCompleteTextView
        multiAutoCompleteTextView.setAdapter(adapter);
        multiAutoCompleteTextView.setTokenizer(new SemicolonTokenizer(';'));


        toggleButton.setOnCheckedChangeListener(this);

        buttonList.setOnClickListener(this);
        buttonSimpleList.setOnClickListener(this);
        buttonCalander.setOnClickListener(this);
        buttonDownload.setOnClickListener(this);

    }


    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (!isChecked) {
            imageButton.setBackgroundResource(R.color.colorBlack);
        } else  {
            imageButton.setBackgroundResource(R.color.colorpurple);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.buttonList:

                Intent intent = new Intent(this, ListActivity.class);
                startActivity(intent);
                break;

            case R.id.buttonSimpleList:

                intent = new Intent(this, SimpleListActivity.class);
                startActivity(intent);
                break;

            case R.id.buttonCalandar:
                intent = new Intent(this, CalendarActivity.class);
                startActivity(intent);

                break;

            case R.id.buttonDownload:
                intent = new Intent(this, DownloadProgressButtonActivity.class);
                startActivity(intent);
                break;

            default:
                break;
        }

    }

    public void doClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.btn_skip:
                intent = new Intent(this, SkipButtonActivity.class);
                startActivity(intent);
                break;
        }
    }
}
